package com.gary.heapJUC;

import java.util.concurrent.CountDownLatch;

/**
 *
 * CountDownLatch, 当计数器小于0的时候再去执行await方法后的逻辑，>0时，调用await的线程阻塞
 * @author peng_rui
 * @date 2022/3/16
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 号同学离开教室。。");
                latch.countDown();
            }, "AA" + i).start();
        }

        latch.await();
        System.out.println(Thread.currentThread().getName() + "关门");
    }
}
